﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.Menus;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.Menus
{
    public class GetRoleMenuCommandHandler : IRequestHandler<GetRoleMenuCommand, APIResult<List<Menu>>>
    {
        private readonly IBaseRepository<Menu> menuRep;

        public GetRoleMenuCommandHandler(IBaseRepository<Menu> menuRep)
        {
            this.menuRep = menuRep;
        }

        public async Task<APIResult<List<Menu>>> Handle(GetRoleMenuCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Menu>> result = new APIResult<List<Menu>>();
            var list=menuRep.GetAll().Result;
            result.data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
